const path = require('path')
const merge = require('webpack-merge')

module.exports = {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  env: {
    BASE_URL: process.env.BASE_URL,
    NODE_ENV: process.env.NODE_ENV,
	HOST: process.env.HOST,
	PORT: process.env.PORT
  },
  server: {
    port: process.env.PORT, // default: 3000
	host: process.env.HOST
  },
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' },
      { name: 'referrer', content: 'no-referrer' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
    'assets/myTools/cssTools/index.styl',
    'assets/fontawesome/css/fontawesome.min.css'
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    { src: '@/plugins/vant-ui', ssr: true },
    { src: '@/plugins/api.js'},
    '@/plugins/vueToolsPlugin.js'	//引入vueTools全局组件
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
    // '@nuxtjs/eslint-module'
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    '@nuxtjs/style-resources',
    'nuxt-purgecss',
  ],

  purgeCSS: {
    enabled: true,
    whitelistPatterns: [/^van/, /^csstoolstag/, /^vt/, /^fa/],
	paths: [
		'assets/myTools/vueTools/**/*.vue'
	],
  },

  /*
  serverMiddleware: [
    '~/api/test'
  ],
  */

  styleResources: {
    stylus: [
      './assets/myTools/cssTools/global.styl'
    ]
  },

  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
	  baseURL: process.env.BASE_URL
  },
  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
	analyze: false,

	// link: https://juejin.im/post/5e012778518825127f085da8
	transpile: [ /vant.*?less/ ],
	cache: false,
	babel: {
	  plugins: [
		['import', {
		  libraryName: 'vant',
		  "style": (name) => {
			return `${name}/style/less.js`
		  }
		}, 'vant']
	  ],
	},

	extend (config, ctx) {



	  config.resolve = merge(config.resolve, {
		alias: {
		  'components': path.resolve(__dirname, 'components'),
		  'assets': path.resolve(__dirname, 'assets'),
		  'pages': path.resolve(__dirname, 'pages'),
		  'http': path.resolve(__dirname, 'http'),
		  'utils': path.resolve(__dirname, 'utils'),
		  'store': path.resolve(__dirname, 'store')
		}
	  })

	  config.module.rules.push({
		test: /\.coffee$/,
		use: ['coffee-loader']
	  })
	}
	}
}
